<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>

    <style>
        
    </style>
</head>

<script>
    

    /* // 示例: 我们来创建并使用一个简单的回调函数
    function needCallback (callback) {
        let myName = 'Fitz'
        callback(myName)
    }

    // 1. 函数由我们自己定义
    let cb = function callbackFunc (parm) {
        console.log(parm)
    }

    // 2. 我们自身没有手动去调用

    needCallback(cb) // 传入回调函数cb

    // 3. 函数(回调)最终却执行了 */



    // ========================== 同步回调 ===================

    var arr = [1, 'good']

    arr.forEach( item => console.log(item) )
    console.log('after forEach')

    /* 
        执行顺序: 
            1
            'good'
            after forEach
    */

    // ========================== 异步回调 ===================

    Promise.resolve('good').then(r => console.log(r))
    console.log('after promise')

    /* 
        执行顺序:
            after promise
            'good'
    */
</script>

<body>
    
</body>

</html>